<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta content="width=device-width, initial-scale=1, maximum-scale=1,
			shrink-to-fit=no" name="viewport">
    <title>书友网首页</title>
    <link rel="stylesheet" href="./assets/css/app.min.css">
    <link rel="stylesheet" href="./assets/css/style.css">
    <link rel="stylesheet" href="./assets/css/components.css">
    <link rel="stylesheet" href="./assets/css/custom.css">
    <link rel='shortcut icon' type='image/x-icon' href='./assets/img/favicon.ico'/>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <style>
        .el-tag + .el-tag {
            margin-left: 10px;
        }
        .button-new-tag {
            margin-left: 10px;
            height: 32px;
            line-height: 30px;
            padding-top: 0;
            padding-bottom: 0;
        }
        .input-new-tag {
            width: 90px;
            margin-left: 10px;
            vertical-align: bottom;
        }
    </style>
    <style>
        [v-cloak]{
            display: none;
        }
    </style>
</head>

<body>
<div id="indexVue" v-cloak>
    <!--<div class="loader"></div>-->
    <div id="app">

        <div class="main-wrapper main-wrapper-1">
            <div class="navbar-bg"></div>

            <user-cart :avatar="user.avatar" :account="user.account"></user-cart>
            <!-- 左侧菜单页 -->
            <div class="main-sidebar sidebar-style-2">
                <aside id="sidebar-wrapper">
                    <div class="sidebar-brand">
                        <a href="Index.html">
                            <img alt="image" src="./assets/img/logo.png" class="header-logo"/>
                            <span class="logo-name">书友网</span>
                        </a>
                    </div>
                    <div class="sidebar-user">
                        <div class="sidebar-user-picture">
                            <img alt="image" :src="user.avatar">
                        </div>
                        <div class="sidebar-user-details">
                            <div class="user-name">{{user.nickName}}</div>
                            <div class="user-role">{{user.email}}</div>
                        </div>
                    </div>
                    <el-menu background-color="#fff" text-color="#000" active-text-color="#409EFF" unique-opened
                             :collapse="isCollapse"
                             :collapse-transition="false"
                             :default-active="activePath">
                        <!-- 一级菜单 -->
                        <template  v-for="item in menuList">
                            <el-submenu v-if="item.children.length > 0" :index="item.id + ''" :key="item.id">
                                <!-- 一级菜单的模板区域 -->
                                <template slot="title">
                                    <i :class="item.icon"></i>
                                    <span>{{item.menuName}}</span>
                                </template>

                                <!-- 二级菜单 -->
                                <el-menu-item v-if="item.children" :index="subItem.path" v-for="subItem in item.children" :key="subItem.id" @click="saveNavState(subItem.path)">
                                    <template slot="title">
                                        <span>{{subItem.menuName}}</span>
                                    </template>
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else  :index="item.path" :key="item.id" @click="saveNavState(item.path)">
                                <!-- 一级菜单的模板区域 -->
                                <template slot="title">
                                    <i :class="item.icon"></i>
                                    <span>{{item.menuName}}</span>
                                </template>
                            </el-menu-item>
                        </template>

                    </el-menu>
                </aside>
            </div>
            <!-- Main Content -->
            <div class="main-content">
                <el-breadcrumb separator-class="el-icon-arrow-right">
                    <el-breadcrumb-item :to="{ path: '/AdminIndex.html' }">首页</el-breadcrumb-item>
                    <el-breadcrumb-item>用户管理</el-breadcrumb-item>
                    <el-breadcrumb-item>全部用户</el-breadcrumb-item>
                </el-breadcrumb>

                <el-card style="margin-top: 20px">
                    <el-form :inline="true" :model="formInline" class="demo-form-inline">
                        <el-form-item label="登录账号">
                            <el-input v-model="formInline.account"  placeholder="用户昵称" clearable  @clear="clear"></el-input>
                        </el-form-item>
                        <el-form-item label="用户昵称">
                            <el-input v-model="formInline.nickName" placeholder="用户昵称" clearable  @clear="clear"></el-input>
                        </el-form-item>
                        <el-form-item label="用户状态">
                            <el-select v-model="formInline.status" clearable  @clear="clear" placeholder="用户状态">
                                <el-option label="全部" value=""></el-option>
                                <el-option label="正常使用" value="1"></el-option>
                                <el-option label="已锁定" value="0"></el-option>
                            </el-select>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="query">查询</el-button>
                            <el-button type="primary" @click="dialUpload = true">导入用户</el-button>
                        </el-form-item>
                    </el-form>
                    <el-table
                            :data="tableData"
                            border
                            size="mini"
                            style="width: 100%" align="center">
                        <el-table-column
                                type="index"
                                label="序号"
                                min-width="5%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="id"
                                label="用户id"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="account"
                                label="登录账号"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="nickName"
                                label="用户昵称"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="email"
                                label="邮箱"
                                min-width="20%" align="center">
                        </el-table-column>
                        <el-table-column
                                prop="status"
                                label="用户状态"
                                min-width="15%" align="center">
                            <!--插槽-->
                            <template slot-scope="scope">
                                <el-switch
                                        v-model="scope.row.status"
                                        active-color="#13ce66"
                                        inactive-color="#ff4949"
                                        @change="userStatusChanges(scope.row)">
                                </el-switch>
                            </template>
                        </el-table-column>
                        <el-table-column
                                label="操作" min-width="20%" align="center">
                            <template slot-scope="scope">
                                <el-button type="info" size="small" icon="el-icon-delete" @click="deleteUser(scope.row)"></el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="block">
                        <el-pagination
                                @size-change="handleSizeChange"
                                @current-change="handleCurrentChange"
                                :current-page="currentPage"
                                :page-sizes="[5, 10, 20, 50]"
                                :page-size="10"
                                layout="total, sizes, prev, pager, next, jumper"
                                :total="total">
                        </el-pagination>
                    </div>
                </el-card>
            </div>
            <my-footer></my-footer>
            <el-dialog
                    title="提示"
                    :visible.sync="dialUpload"
                    width="30%">
                <el-upload
                        class="upload-demo"
                        drag
                        action="/file/uploadFile"
                        :on-success="handleAvatarSuccess"
                        multiple>
                    <i class="el-icon-upload"></i>
                    <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
                </el-upload>

                <span slot="footer" class="dialog-footer">
    <el-button @click="dialUpload = false">取 消</el-button>
    <el-button type="primary" @click="dialUpload = false">确 定</el-button>
  </span>
            </el-dialog>
        </div>
    </div>
</div>

<script src="./common/js/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="./compont/foot.js"></script>
<script src="./compont/UserCart.js"></script>
<script src="./common/js/common.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/layer/2.3/layer.js"></script>
<script src="https://unpkg.com/element-ui/lib/index.js"></script>

<!-- General JS Scripts -->
<script src="./assets/js/app.min.js"></script>
<!-- JS Libraies -->
<script src="./assets/js/page/index2.js"></script>
<script src="./assets/js/page/todo.js"></script>
<!-- Template JS File -->
<script src="./assets/js/scripts.js"></script>
<!-- Custom JS File -->
<script src="./assets/js/custom.js"></script>



<script>
    const vm = new Vue({
        el: "#indexVue",
        data: {
            dialUpload : false,
            user :{
                avatar : '',
                nickName:'',
                userId:'',
                account:'',
            },
            activeIndex2: '1',
            // 左侧菜单数据
            menuList: [],
            // 是否折叠
            isCollapse: false,
            // 被激活的链接地址
            activePath: '',
            formInline:{
                nickName:'',
                gender:'',
                status:'',
                account:'',
                page : 1,
                size : 10
            },
            currentPage : 1,
            total : 0,
            tableData: [],
        },

        created() {
            this.getMenuList()
            this.getUserInfoList();
            this.getUserList()
            this.activePath = window.localStorage.getItem('activePath')
        },
        methods:{
            getUserInfoList(){
                var userId = localStorage.getItem("userId");
                var account = localStorage.getItem("account");
                var nickName = localStorage.getItem("nickName");
                var avatar = localStorage.getItem("avatar");
                this.user.account = account;
                this.user.userId = userId;
                this.user.nickName = nickName;
                this.user.avatar = avatar;
            },
            handleAvatarSuccess(res, file) {
                const that = this;
                that.dialUpload = false;
                if (res.result == true){
                    layer.msg(res.data,{icon:1,time:2000},function () {
                        that.getUserList();
                    });
                }else{
                    layer.msg("上传失败",{icon:2});
                }
            },
            getUserList(){
                const that = this;
                const queryParam = {
                    "nickName": that.formInline.nickName,
                    "gender":that.formInline.gender,
                    "status":that.formInline.status,
                    "account":that.formInline.account,
                    "page": that.formInline.page,
                    "size":that.formInline.size
                };
                HttpGet("/user/getUserList",queryParam,function (res) {
                    if(res.result == true){
                        that.tableData = res.data.data;
                        that.total = res.data.total;
                    }else{
                        layer.msg("查询失败，请稍后重试......",{icon:2,time:1500});
                    }
                })
            },
            userStatusChanges(user){
                const that = this;
                $.ajax({
                    url : "/user/changeStatus/"+user.id+"/"+user.status,
                    async : false,
                    type : "POST",
                    contentType : 'application/json',
                    dataType : 'json',
                    success : function(result) {
                        if(result.result == true){
                            layer.msg("更改成功",{icon:1,time:1500});
                            that.query();
                        }else{
                            layer.msg("更改失败，请稍后重试......",{icon:2,time:1500});
                        }

                    }
                });
            },
            clear (){
                this.getUserList();
            },

            genderFormatter(row, column){
                return row.user.gender == 1 ? "男" : row.user.gender == 2 ? "女" : "用户未更新";
            },

            handleSizeChange(val) {
                const size = this.formInline.size;
                if (val === size){
                    return;
                }
                this.formInline.size = val;
                this.getUserList();
            },
            handleCurrentChange(val) {
                const page = this.formInline.page;
                if (val === page){
                    return;
                }
                this.formInline.page = val;
                this.getUserList();
            },
            query (){
                this.formInline.page = 1;
                this.formInline.size = 10;
                this.getUserList();
            },
            getMenuList(){
                const that = this;
                HttpGet("/menu/getList",null,function (res) {
                    if (res.result == true){
                        that.menuList = res.data;
                    }else{
                        layer.msg("获取列表失败！请刷新重试~",{icon:2,time:2000})
                    }
                })
            },
            // 点击按钮，切换菜单的折叠与展开
            toggleCollapse() {
                this.isCollapse = !this.isCollapse
            },
            // 保存链接的激活状态
            saveNavState(activePath) {
                window.localStorage.setItem('activePath', activePath)
                this.activePath = activePath
                window.location.href = activePath;
            }
        },
    })
</script>
</body>

</html>
